import React from "react";
import SourceTop from "./source/sourceTop";
import style from './source.module.scss';
import {getBookList} from "../../http";
class Source extends React.PureComponent{
    constructor(props) {
        super(props);
        this.state = {
            title:'',
            item:[],
            vedioSrc:''
        }
        this.itemList = []
    }
    componentDidMount() {
        getBookList(this.props.location.state).then(data=>{
            let arr = JSON.parse(data.content).comp
            arr.forEach(value=>{
                if(value.type!=='img'){
                    this.setState({
                        vedioSrc:value.attrs.src
                    })
                }
                this.itemList.push(value.attrs.src)
            })
            this.setState({
                item: this.itemList,
                title:data.title,
            })
        }).catch(err=>{
            console.log(err)
        })

    }
    render() {
        return (
            <div className={style.source}>
                <SourceTop item = {this.state.item} title={this.state.title} vedie={this.state.vedioSrc}/>
            </div>
        );
    }
}
export default Source